cmp V2.0 (2000-11-26)

cmp is a program, which compares files in two directories (or trees). That can be very useful, e.g. to examine in a backup, which files have been changed or rather are new.
With cmp it is also possible, to compare two files and display the differences (hex-dump).
With cmp and the device-handler (AmiNet:disk/misc/dev_hdl.lha) you can also compare disks/harddisks byte for byte.

The latest Version can be found under:
http://www.kazik.de/alex/cmp
My HomePage: http://www.kazik.de/alex/



Table of contents



Requirements

AmigaOS 2.1 or better.


Installation

Just copy the program and the documentation wherever you want.


Disclaimer
This software is subject to the "Standard Amiga FD-Software Copyright Note".
It is GIFTWARE/MAILWARE as defined in paragraph 4g/4b.
For more information please read "AFD-COPYRIGHT" (Version 1.4 or higher).



Usage

Since V2.0 is cmp localized. All texts in this documentaion are the english ones.

With the first two parameters you have to say cmp, what should be compared. The parameters can be:
Notice: A file could not be compared with a pattern.

A comparison can have one of the following results:
Q:The two files are equal.
L:The two files are different in length.
C:The two files have the same length, but they are different in contents.
D:The two files have different length and contents.
A:A file/directory in the directory (-tree) B does not exist in A.
B:A file/directory in the directory (-tree) A does not exist in B.
W:It was tried to compare a file with a directory (object wrong type).
E:Another error has occured, e.g. a read error.
S:A is a truncated version of B *L
T:B is a truncated version of A *L
O:File Comment mismatch *O
P:Protection-Bits mismatch *P
0:Errormessage 212: Object wrong type (A=DIR, B=FILE) *W
1:Errormessage 212: Object wrong type (A=FILE, B=DIR) *W
2:Errormessage 205: Object not found (A=DIR, B=-) *A
3:Errormessage 205: Object not found (A=FILE, B=-) *A
4:Errormessage 205: Object not found (A=-, B=DIR) *B
5:Errormessage 205: Object not found (A=-, B=FILE) *B
6:Errormessage 205: Object not found (A=NEWDIR) *N
7:Errormessage 205: Object not found (A=NEWFILE) *N
8:Errormessage 205: Object not found (B=NEWDIR) *N
9:Errormessage 205: Object not found (B=NEWFILE) *N

*L, *W, *A, *B = With the option DETAIL will be the results LWAB replaced by the more exact one ST012345.

*N = New results, added by the options NEWDIR/NEWFILE.

*O = New results, added by the option COMMENT.

*P = New results, added by the option PROTBITS.

If some of the new results are missing in the following text: They will be handled like the simple versions. And N will be handled like A/B.

Only the most important parameters will be mentioned here, the detailed usage of the parameters is described on the following page. All parameters are written bold and BIG.

For cmp is an extended help available: Call cmp (in a CLI) with parameter "?" and enter at the following request another "?".

The output from cmp results like this:
If the two files should be compared in difference (C,D) and an output of the difference is desired, a hex-dump of the different lines will be displayed. The differences will be marked white ( example ). The hex-dump can be switched on/off with the option DUMP. For a comparison of two files, the hex-dump will be switched on by default.
A hex-dump can be aborted with CTRL-D, but the comparison will be continued.
If the option DUMP is switched off, the files, which have different length will not be compared whether they have different contents. Also see CHECKD.

After the hex-dump-output (if switched on) the filename and the result will be displayed in plain text. The text is, depending on the result, one of the following:
Q:[no text]
L:Difference in length
C:Difference in contents
D:Difference in length&contents
A,B,W,E:The corresponding error messages (see above), since workbench 2.1 localized.

More results you'll find here .

Notice: Two files with equal sizes and dates, will be shown by cmp as equal, and the contents will not be compared. Also see CHECKD.

The output can be adjusted completely with the option LFORMAT to the wishes of the user.

After completion of cmp the returncode will be set as follows:
0:All files are equal.
5:One or more files are different (LCDOP).
6:The file A is a truncated version of file B (S).
7:The file B is a truncated version of file A (T).
10:One or more files could not be found / are of wrong type (ABW).
15:Another error had occured (E).
20:A serious error occured / the comparison would be aborted.

The values 5-15 will be only set, if the output will be made (see SHOW). Also see NORC.

After the comparison of directories a short statistic will be displayed. Also see NOSTAT.

With the option SHOW you can specify, which messages should be displayed.

With the option ABORT you can say cmp, on which results the comparison should be aborted.

With the option ALL you can switch on, that cmp should recursively compare the two directories.

Normally, links to directories will be completely ignored. For this, read HLINK and SLINK.

For more detailes about the syntax of the options, please read the next page.


Parameters

The syntax for the usage of cmp is:
cmp A/A,B/A,ALL/S,SHOW/K,ABORT/K,DUMP/N,CHECKD/S,ONLYA/S,HLINK/S,SLINK/S, LFORMAT/F,NOSTAT/S,NORC/S,DETAIL/S,NEWDIR/N,NEWFILE/S,REVADIR/S,REVBDIR/S, DUMPALL/S,SKIPFIRSTNBYTES=SKIP/K/N,COMMENT=COM/K/N
When you start cmp with parameter "?", the above shown syntaxline will be shown to you and you can still enter your parameters. If you enter at this moment another "?", the extended help will be displayed to you.

A/AThe first file/directory/pattern (see usage).
B/AThe second file/directory/pattern (see usage).
ALL/SThe two directories will be compared recursively.
SHOW/KWhich outputs should be made or rather should be suppressed. The (to be given) parameter is a string, which contains the outputs. The outputs will be specified with the results (QLCDABWE). The meaning of the individual results is described in the part usage. A leading "~" negates the input. By default, everything will be displayed.
ABORT/KOn which results the comparison should be aborted. The details are corresponding to the details of SHOW. By default, it will be never aborted.
DUMP/NWhether a hex-dump should be displayed. In case of a positive number, max. DUMP different lines will be displayed. Equal lines will be never displayed. In case of a negative number, all different lines will be displayed. In case of zero, the hex-dump will be disabled. When comparing two files, DUMP will be set to -1, by default. Otherwise to 0.
A hex-dump can be aborted with CTRL-D, but the comparison will be continued.
CHECKD/SIf two compared files are different in length, by default they will be not checked, whether they are different in contents (up to the length difference). Besides, files will not be checked, if they are of equal date and length. With this option you can activate this feature, which mostly makes no sense and only costs time. If the DUMP option is different from 0, it will be activated automatically.
ONLYA/SNormally, comparing two directories, all files (directories) in the 1st tree will be compared with the 2nd and the other way. If this option is activated, only the 1st directory will be searched and compared with the 2nd. Files/directories, which are in the 2nd directory but not in the 1st one, will not be displayed/searched.
HLINK/SWith links it is possible to build a cyclic structure, which will be not recognized during a comparison, and will make cmp running in a loop forever. Because of this, normally cmp will not follow hardlinks to directories. Activating this option, it is possible to follow hardlinks to directories.
Links to files will be checked.
SLINK/SLike HLINK, whether softlinks to directories should be followed.
LFORMAT/FThis is the probably most extensive option of cmp. With it, the look of the output can be changed. But not the look of the hex-dump. How it exactly works, you can read on the following page.
NOSTAT/SSwitches off the statistics.
NORC/SIf this option is enabled the resultcode is always 0, except of serious errors or user abort.
This option is intended for the usage of cmp in DOpus and ARexx scripts, because there may occur problems or undesired effects with a non-zero return code.
DETAIL/SWith this option the results ABLW will be more detailed.
The new results for L: (And their also new RC-Codes.)
S: A is a truncated version of B
T: B is a truncated version of A
The new results for W:
0: Errormessage 212: Object wrong type (A=DIR, B=FILE)
1: Errormessage 212: Object wrong type (A=FILE, B=DIR)
The new results for AB:
2: Errormessage 205: Object not found (A=DIR, B=-)
3: Errormessage 205: Object not found (A=FILE, B=-)
4: Errormessage 205: Object not found (A=-, B=DIR)
5: Errormessage 205: Object not found (A=-, B=FILE)
NEWDIR/NAlso directory structures, which doesn't exists in the other tree will be displayed. You have to specify a maximal depth. A depth of <= 0 will mean unlimited! This option is only useful together with ALL. There are new results (68) for this Option. ( see output )
An example for this option can be found here .
NEWFILE/SDisplays also the files in the directories, added by NEWDIR.
There are new results (79) for this Option. ( see Output )
An example for this option can be found here .
REVADIR/S,REVBDIR/SWith the options NEWDIR and NEWFILE normally the new directory will be displayed first, and then it's contents. With this option you can reverse it.
An example for this option can be found here .
DUMPALL/SAll lines - not only different - will be displayed.
SKIPFIRSTNBYTES=SKIP/K/NThe first N bytes of each file will be skipped. You'll receive an result L if the file is too short.
COMMENT=COM/K/N
  • COM<0: Only file comments will be compared. (no contents, ...)
  • COM>0: If two files are identical, the file comments will be checked.
  • COM=0: No comparison of the file comments. (default)

If COM is 1 or -1 the comparison is case insensitive, else it's case sensitive.

In case of a mismatch the result O will be returned.
PROTBITS/SIf switched on, protection bits mismatches are displayed.



Output

The output can be changed by the option LFORMAT.

The rest of the parameters will be automatically interpreted by cmp as LFORMAT. Therefore it is not necessary, to enter LFORMAT and it is also not necessary, to quote the option.

The following options are supported in the output:
%nName
%pPath (QLCD: relative to base, ABWE: absolute)
%tPath (QLCD: relative to base, ABWE: with a leading "A:"/"B:")
%PPath + Name (see %p)
%TPath + Name (see %t)
%eError as text
%EError as number
%rResult (QLCDABWE)
%RPath relative to base
%aAbsolute path in A
%bAbsolute path in B
%%"%"
*n, *NA new line will be inserted
*e, *EAn ESC character will be inserted
**"*"

The results have the following error numbers/texts:
Q:700""
L:701"Difference in length"
C:702"Difference in contents"
D:703"Difference in length&contents"
A:704Errormessage 205: Object not found
B:705Errormessage 205: Object not found
S:706"A is a truncated version of B"
T:707"B is a truncated version of A"
O:708"Difference in comment"
P:709"Difference in protection bits"
W:212Errormessage 212: Object wrong type
E:xxxErrormessage xxx
0:800Errormessage 212: Object wrong type (A=DIR, B=FILE)
1:801Errormessage 212: Object wrong type (A=FILE, B=DIR)
2:802Errormessage 205: Object not found (A=DIR, B=-)
3:803Errormessage 205: Object not found (A=FILE, B=-)
4:804Errormessage 205: Object not found (A=-, B=DIR)
5:805Errormessage 205: Object not found (A=-, B=FILE)
6:806Errormessage 205: Object not found (A=NEWDIR)
7:807Errormessage 205: Object not found (A=NEWFILE)
8:808Errormessage 205: Object not found (B=NEWDIR)
9:809Errormessage 205: Object not found (B=NEWFILE)

Like in C usual, it is possible to specify the options. This will be done by inserting format options between "%" and the option.

A number says, how much characters long the option should be displayed. If the number is negative, the output is left justified, otherwise right.

With a leading "!" as format option, the output will be truncated to the specified width of the following number. In case of %p,%t,%P,%T the output will be cut of left, using %n,%e right. In case of %E,%r this option will be ignored.


History

2.02000-11-26
  • Added PROTBITS
  • cmp is now GIFTWARE/MAILWARE
  • Localized (now OS 2.1 is required)
  • German Catalog available
  • Support-Site: http://www.kazik.de/alex/cmp
1.92000-10-08
  • Added COMMENT
  • Changed the doctument format to HTML
1.82000-02-11
  • Updated the documentation
1.72000-01-25
  • Improved DETAIL (S/T results)
1.6-internal-
  • Added DETAIL, NEWDIR, NEWFILE, REVADIR, REVBDIR, DUMPALL, SKIPFIRSTNBYTES
1.51999-04-07
  • The 020-Version is now residentable (useful for EqFiles.rexx)
  • use "lha x -a" to extract the archive, or "protect cmp p add" to make it residentable
  • E-Mail/HomePage has changed!
1.41997-05-21
  • Outputs statistics when comparing directories
  • Option NOSTAT switches off the statistics
  • Added the option NORC
  • Removed two bugs in the 68000 version
1.31997-04-16
  • Removed a new bug
  • 68000 version added again (V1.2 was only 020+)
  • Colored the output a little bit more
  • Corrected the guide/readme
  • If two files are of equal sizes and dates, they will be shown as equal
1.21997-04-10
  • Fixed a little bug
  • Recompiled with StormC and the stormamiga.lib (smaller & faster)
1.11997-02-28
  • Improved the option DUMP
1.01997-02-18
  • First release



Tanks to

Andreas Mayer-Gürr
for proof-reading, correction of the guide and beta testing

Nils Goers
for an idea for the option DUMP

Fulvio Peruggi
for some bug reports and the idea with the colors, beta testing, much more ideas and for proof-reading

Matthias Henze
for the stormamiga.lib, which I'am using since V1.2

Simon N Goodwin
for the idea of the date comparison

Henry Sopko
for 68000 beta testing

Thomas Chen
for the idea of the comment/protection bits comparison


Dump Example

DUMP: Disk.info                   Test.info                   
0010: 00000002 00000A40 .......@  00000002 0000099B ........
0018: 00000CBF 00000106 ...¿....  000001B6 00000017 ......
0020: 000003E9 00000A40 ...é...@  000003E9 0000099B ...é....
0028: 2C780004 2A4F226E ,x..*O"n  48E77EFE 24482400 Hç~þ$H$.
0030: 01144AA9 00AC6652 ..J©.¬fR  49F90000 00002C78 Iù....,x
0038: 41E9005C 2F084EAE Aé.\/.N®  000447F9 000005AC ..Gù...¬
Disk.info: Found 31 differences in contents&length until abort



Complex Example

Here is a complex example, how to use cmp as an updater. The following ARexx script will modify the B-Tree that it is exactly like the A-Tree. Only all changed files will copied. It is an ARexx-Script, and it's (hopefully) a help. Without DETAIL it's not possible to distinguish between (missing/useless) dirs and files. More information at the end of the following listing. This is the listing of "update1.rexx".
/*
** Update only all neccesary files from dir A -> dir B
**                 ©1999/2000 ALeX Kazik
*/

/* IMPORTANT: the src/dst dir MUST end with a colon or slash and MUST NOT be empty! */

/* SOURCE directory */
src = 'a/'

/* DESTINATION directory */
dst = 'b/'

/* the script to create, and which will be executed */
script = 'T:script'

/* SKIP the first N bytes */
skip = 0

/* temporary file */
tmpfile = 'T:update.tmp'

/*
** The main-program
*/

ADDRESS COMMAND

cmp 'A="' || src || '" B="' || dst || '" all nostat norc skipfirstnbytes=' || SKIP ,
    || ' newdir=10 newfile revbdir detail lformat %r%R%n >"' || TMPFILE || '"'
IF RC >= 20 THEN DO
	SAY 'Error while executing cmp'
	EXIT RC
END

CALL OPEN(tmp, tmpfile, 'read')
CALL OPEN(scr, script, 'write')

eq = 0

DO UNTIL EOF(tmp)
  act = READCH(tmp, 1)
  file = READLN(tmp)
  IF act = '' THEN
    BREAK
  ELSE IF act = 'Q' THEN
    eq = eq + 1
  ELSE IF (act = 'A') | (act = '5') | (act = '9') THEN DO
    SAY 'File to remove: ' || file
    CALL WRITELN(scr, 'delete "' || dst || file || '" quiet')
  END
  ELSE IF (act = '4') | (act = '8') THEN DO
    SAY 'Dir to remove: ' || file
    CALL WRITELN(scr, 'delete "' || dst || file || '" quiet')
  END
  ELSE IF (act = 'B') | (act = '3') | (act = '7') THEN DO
    SAY 'New File: ' || file
    CALL WRITELN(scr, 'copy "' || src || file || '" "' || dst || file || '"')
  END
  ELSE IF (act = '2') | (act = '6') THEN DO
    SAY 'New Dir: ' || file
    CALL WRITELN(scr, 'makedir "' || dst || file || '"')
  END
  ELSE IF (act = 'E') | (act = '0') | (act = '1') THEN DO
    SAY 'Error/Warning at dir/file: ' || file
    EXIT 20
  END
  ELSE IF (act = 'L') | (act = 'C') | (act = 'D') | (act = 'S') | (act = 'T') THEN DO
    SAY 'File to Update: ' || file
    CALL WRITELN(scr, 'copy "' || src || file || '" "' || dst || file || '"')
  END
  ELSE DO
    SAY 'Unknown Symbol >' || act || '<'
    CALL CLOSE(tmp)
    CALL CLOSE(scr)
    EXIT 20
  END
END

SAY eq || ' Equal files.'

CALL CLOSE(tmp)
CALL CLOSE(scr)

/*
** executing the changes
*/

execute '"' || script || '"'

/*
** That's all.
*/

Ok. Did you now understand, for what I've created NEWDIR/NEWFILE? Not? Just remove DETAIL and examine the created files against those before...

REVBDIR is used here, because the entries of a directory should be removed before the directory can be removed.

This is only the simple version. The more powerful version can be found here: "update2.rexx".

That version is also able to generate a FTP-Script, I use it to update my web-pages.

©2000 ALeX Kazik · last update 26-Nov-2000